package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        if(member.getPassword()!=null){
            //对密码进行加密
            member.setPassword(MD5Utils.md5(member.getPassword()));
        }
        memberDao.add(member);

    }

    @Override
    public List<Integer> findMemberCountByMonth(List<String> month) {
        List<Integer> list=new ArrayList<>();
        for (String s : month) {
            s=s+"31";//xxxx.xx.31
            int count=memberDao.findMemberCountBeforeDate(s);
            list.add(count);
        }
        return list;
    }
}
